defmodule House.BaseDataTest do
  use House.DataCase

  alias House.BaseData
  alias House.BaseData.Photo

  @create_attrs %{kind: 42, url: "some url"}
  @update_attrs %{kind: 43, url: "some updated url"}
  @invalid_attrs %{kind: nil, url: nil}

  def fixture(:photo, attrs \\ @create_attrs) do
    {:ok, photo} = BaseData.create_photo(attrs)
    photo
  end

  test "list_photos/1 returns all photos" do
    photo = fixture(:photo)
    assert BaseData.list_photos() == [photo]
  end

  test "get_photo! returns the photo with given id" do
    photo = fixture(:photo)
    assert BaseData.get_photo!(photo.id) == photo
  end

  test "create_photo/1 with valid data creates a photo" do
    assert {:ok, %Photo{} = photo} = BaseData.create_photo(@create_attrs)
    assert photo.kind == 42
    assert photo.url == "some url"
  end

  test "create_photo/1 with invalid data returns error changeset" do
    assert {:error, %Ecto.Changeset{}} = BaseData.create_photo(@invalid_attrs)
  end

  test "update_photo/2 with valid data updates the photo" do
    photo = fixture(:photo)
    assert {:ok, photo} = BaseData.update_photo(photo, @update_attrs)
    assert %Photo{} = photo
    assert photo.kind == 43
    assert photo.url == "some updated url"
  end

  test "update_photo/2 with invalid data returns error changeset" do
    photo = fixture(:photo)
    assert {:error, %Ecto.Changeset{}} = BaseData.update_photo(photo, @invalid_attrs)
    assert photo == BaseData.get_photo!(photo.id)
  end

  test "delete_photo/1 deletes the photo" do
    photo = fixture(:photo)
    assert {:ok, %Photo{}} = BaseData.delete_photo(photo)
    assert_raise Ecto.NoResultsError, fn -> BaseData.get_photo!(photo.id) end
  end

  test "change_photo/1 returns a photo changeset" do
    photo = fixture(:photo)
    assert %Ecto.Changeset{} = BaseData.change_photo(photo)
  end
end
